package com.xiaobai.service.course;

import com.alibaba.fastjson.JSON;
import com.xiaobai.common.CommonXQ;
import com.xiaobai.dao.StudentCourseDao;
import com.xiaobai.pojo.ClassTask;
import com.xiaobai.pojo.StudentCourse;
import com.xiaobai.service.UnitsCourseService;
import com.xiaobai.units.HttpUnits;
import com.xiaobai.units.HttpUnits_V2;
import com.xiaobai.vo.AllCourseAllList;
import com.xiaobai.vo.AllCourseWeekList;
import com.xiaobai.vo.CourseItem;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class CourseServiceImpl implements ICourseService {
    
    @Autowired
    private StudentCourseDao studentCourseDao;

    @Autowired
    private UnitsCourseService unitsCourseService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public String getCourseAll(String jsessionid) {

        String coxq= CommonXQ.KCB;

        //根据jsessionid和week去获取对应周次的课表
        //redis控制一个学期
        String url="https://jwxt.gdupt.edu.cn/xsgrkbcx!getKbRq.action?xnxqdm="+coxq;//无week,查一学期的

        // 经过 jsessionId 冲突(推测), 所以改成httpClient
//        String result=HttpUnits.gyGet(url,jsessionid,null);
        String result = HttpUnits_V2.commonGyGet(url, null, jsessionid);

        return result;
    }

//    @Override
//    public AllCourseAllList getAllCourse(String student_id, String jsessionid) {
//
//        AllCourseAllList allCourseAllList=new AllCourseAllList();
//
//        Long start=System.currentTimeMillis();
//
//        for (int i=0;i<20;i++){
//
//            log.info("次数:"+i);
//
//            String str=getCourseByWeek(jsessionid);//查询出的数据i+1周次(总共20周)
//
//            if(StringUtils.isBlank(str)){
//                AllCourseWeekList allCourseWeekList=new AllCourseWeekList();
//                allCourseAllList.getAllCourseWeekLists().set(i,allCourseWeekList);
//                continue;
//            }
//
//            int startIndex=1;
//            int endIndex=str.indexOf(",[{\"xqmc\"");
//
//            String resultJSON=str.substring(startIndex,endIndex);
//
//            List<String> list=JSON.parseArray(resultJSON,String.class);
//
//            List<CourseItem> courseItemsList=new ArrayList<>();
//
//            List<Integer> listIndex=new ArrayList<>();
//
//            list.forEach(js->{
//                CourseItem courseItem= JSON.parseObject(js,CourseItem.class);
//                listIndex.add(courseItem.getIndexItem());//放入已有下标
//                courseItemsList.add(courseItem);//放入正确的对象集合
//            });
//
//            /**
//             * 此处是周专场!!!
//             */
//            AllCourseWeekList allCourseWeekList=new AllCourseWeekList();
//
//            Integer index=null;
//
//            for(int j=0;j<listIndex.size();j++){
//                index=listIndex.get(j);//获取当前课程对应周里面的下标
//                CourseItem courseItem=courseItemsList.get(j);
//                if(courseItem.getCon()){////送了!多加一节!  十一十二节除外
//                    allCourseWeekList.getIndexCourseList().set(index+1,courseItem);
//                }
//                allCourseWeekList.getIndexCourseList().set(index,courseItem);//存入对应下标课!
//            }
//            allCourseAllList.getAllCourseWeekLists().set(i,allCourseWeekList);
//        }
//
//        /**
//         * 还没存入数据库呢
//         */
//
//        log.info("花费时间:{}秒+{}毫秒",(System.currentTimeMillis()-start)/1000,(System.currentTimeMillis()-start)%1000);
//
//        return allCourseAllList;
//
//    }

    @Override
    public AllCourseAllList getAllCourse(String student_id, String jsessionid) {

        AllCourseAllList allCourseAllList=new AllCourseAllList();

//        for(int i=0;i<20;i++){
//            AllCourseWeekList allCourseWeekList=new AllCourseWeekList();
//            allCourseAllList.getAllCourseWeekLists().set(i,allCourseWeekList);//装填完毕,后面对周集合操作即可
//        }

        String str=getCourseAll(jsessionid);//查询出一学期的数据,zc为空即可
//        String str="";
        //刚开学时有人登录了要查课表数据,直接查20周查不到,就去查上课任务
        if(StringUtils.isBlank(str)){
            AllCourseAllList allCourseByClassTask = getAllCourseByClassTask(student_id, jsessionid);
            return allCourseByClassTask;
        }

        Integer startIndex=1;

        Integer endIndex=str.indexOf(",[]]");

        String resultJSON=str.substring(startIndex,endIndex);

        resultJSON=resultJSON.replace("&mdash;","");

        List<String> list=JSON.parseArray(resultJSON,String.class);

        List<CourseItem> courseItemList=new ArrayList<>();

        list.forEach(js->{
            CourseItem courseItem= JSON.parseObject(js,CourseItem.class);
            courseItemList.add(courseItem);//放入所有的课表对象
        });


        assembleCourse(allCourseAllList,courseItemList);
        /**
         * 上面就是一学期的JSON数据
         * 1.截取
         * 2.转List(一个下标对应一个课的信息)
         * 3.创建一个CourseItem的集合,把上面的ListJSON转为对象
         * 4.遍历上面对象即可,根据zc+index放入对应的周集合且位置对应周集合的下标
         * 5.遍历完即可(我们在一开始就将总集合+周集合创建好,并且将周集合放入总集合)
         */

        /**
         * 异步存入数据库
         * !!!!!!!!!切记不可在一个类中两个方法调用异步,不然异步会失效!!!
         */

        unitsCourseService.saveCourse(allCourseAllList,student_id);

        return allCourseAllList;

    }

    private void assembleCourse(AllCourseAllList allCourseAllList,
                                List<CourseItem> courseItemList){
        courseItemList.forEach(cs->{
            //根据(zc-1)+getIndexItem放入对应的周且下标也对应,记得可能要多送一节

            Integer zc=Integer.parseInt(cs.getZc());

            switch (zc){
                case 1:
                    allCourseAllList.getOneCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getOneCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 2:
                    allCourseAllList.getTwoCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getTwoCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 3:
                    allCourseAllList.getThreeCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getThreeCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 4:
                    allCourseAllList.getFourCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getFourCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 5:
                    allCourseAllList.getFiveCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getFiveCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 6:
                    allCourseAllList.getSixCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getSixCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 7:
                    allCourseAllList.getSevenCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getSevenCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 8:
                    allCourseAllList.getEigCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getEigCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 9:
                    allCourseAllList.getNineCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getNineCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 10:
                    allCourseAllList.getTenCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getTenCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 11:
                    allCourseAllList.getElevenCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getElevenCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 12:
                    allCourseAllList.getTwelveCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getTwelveCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 13:
                    allCourseAllList.getThirteenCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getThirteenCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 14:
                    allCourseAllList.getFourteenCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getFourteenCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 15:
                    allCourseAllList.getFifteenCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getFifteenCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 16:
                    allCourseAllList.getSixteenCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getSixteenCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 17:
                    allCourseAllList.getSeventeenCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getSeventeenCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 18:
                    allCourseAllList.getEighteenCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getEighteenCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 19:
                    allCourseAllList.getNineteenCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getNineteenCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
                case 20:
                    allCourseAllList.getTwentyCourseWeekList()
                            .getIndexCourseList()
                            .set(cs.getIndexItem(),cs);//放入对应周及其对应下标

                    if(cs.getIsContinuity()){
                        //如果是连续课,并且后面连课不是11,12节就多加一节课给周里面
                        allCourseAllList.getTwentyCourseWeekList()
                                .getIndexCourseList()
                                .set(cs.getIndexItem()+1,cs);//连课后面那节下标+1
                    }
                    break;
            }
        });
    }

    @Override
    public void updateWeekCourse(String student_id, String week, String jsonList) {

        StudentCourse studentCourse=new StudentCourse();
        studentCourse.setConnect(jsonList);
        studentCourse.setWeek(Integer.parseInt(week));
        studentCourse.setStudentId(student_id);

        studentCourseDao.updateByStudentIdZidingyi(studentCourse);
    }

    @Override
    public AllCourseAllList getAllCourseByDb(String student_id) {

        AllCourseAllList allCourseAllList=new AllCourseAllList();

        //这里得批量查出数据
        List<StudentCourse> list=studentCourseDao.getAllCourseListByStudentId(student_id);
        //查出的课表,从小周到大周

        if(list==null||list.size()<1){
            return null;
        }

        for(int i=1;i<=20;i++){

            switch (i){
                case 1:
                    String r1=list.get(0).getConnect();
                    List<String> l1=JSON.parseArray(r1,String.class);
                    List<CourseItem> c1=new ArrayList<>();
                    for(int j=0;j<l1.size();j++){
                        c1.add(JSON.parseObject(l1.get(j),CourseItem.class));
                    }

                    AllCourseWeekList oneCourseWeekList=new AllCourseWeekList();
                    oneCourseWeekList.setIndexCourseList(c1);
                    allCourseAllList.setOneCourseWeekList(oneCourseWeekList);
                    break;
                case 2:
                    String r2=list.get(1).getConnect();
                    List<String> l2=JSON.parseArray(r2,String.class);
                    List<CourseItem> c2=new ArrayList<>();
                    for(int j=0;j<l2.size();j++){
                        c2.add(JSON.parseObject(l2.get(j),CourseItem.class));
                    }

                    AllCourseWeekList twoCourseWeekList=new AllCourseWeekList();
                    twoCourseWeekList.setIndexCourseList(c2);
                    allCourseAllList.setTwoCourseWeekList(twoCourseWeekList);
                    break;
                case 3:
                    String r3=list.get(2).getConnect();
                    List<String> l3=JSON.parseArray(r3,String.class);
                    List<CourseItem> c3=new ArrayList<>();
                    for(int j=0;j<l3.size();j++){
                        c3.add(JSON.parseObject(l3.get(j),CourseItem.class));
                    }

                    AllCourseWeekList threeCourseWeekList=new AllCourseWeekList();
                    threeCourseWeekList.setIndexCourseList(c3);
                    allCourseAllList.setThreeCourseWeekList(threeCourseWeekList);
                    break;
                case 4:
                    String r4=list.get(3).getConnect();
                    List<String> l4=JSON.parseArray(r4,String.class);
                    List<CourseItem> c4=new ArrayList<>();
                    for(int j=0;j<l4.size();j++){
                        c4.add(JSON.parseObject(l4.get(j),CourseItem.class));
                    }

                    AllCourseWeekList fourCourseWeekList=new AllCourseWeekList();
                    fourCourseWeekList.setIndexCourseList(c4);
                    allCourseAllList.setFourCourseWeekList(fourCourseWeekList);
                    break;
                case 5:
                    String r5=list.get(4).getConnect();
                    List<String> l5=JSON.parseArray(r5,String.class);
                    List<CourseItem> c5=new ArrayList<>();
                    for(int j=0;j<l5.size();j++){
                        c5.add(JSON.parseObject(l5.get(j),CourseItem.class));
                    }

                    AllCourseWeekList fiveCourseWeekList=new AllCourseWeekList();
                    fiveCourseWeekList.setIndexCourseList(c5);
                    allCourseAllList.setFiveCourseWeekList(fiveCourseWeekList);
                    break;
                case 6:
                    String r6=list.get(5).getConnect();
                    List<String> l6=JSON.parseArray(r6,String.class);
                    List<CourseItem> c6=new ArrayList<>();
                    for(int j=0;j<l6.size();j++){
                        c6.add(JSON.parseObject(l6.get(j),CourseItem.class));
                    }

                    AllCourseWeekList sixCourseWeekList=new AllCourseWeekList();
                    sixCourseWeekList.setIndexCourseList(c6);
                    allCourseAllList.setSixCourseWeekList(sixCourseWeekList);
                    break;
                case 7:
                    String r7=list.get(6).getConnect();
                    List<String> l7=JSON.parseArray(r7,String.class);
                    List<CourseItem> c7=new ArrayList<>();
                    for(int j=0;j<l7.size();j++){
                        c7.add(JSON.parseObject(l7.get(j),CourseItem.class));
                    }

                    AllCourseWeekList sevenCourseWeekList=new AllCourseWeekList();
                    sevenCourseWeekList.setIndexCourseList(c7);
                    allCourseAllList.setSevenCourseWeekList(sevenCourseWeekList);
                    break;
                case 8:
                    String r8=list.get(7).getConnect();
                    List<String> l8=JSON.parseArray(r8,String.class);
                    List<CourseItem> c8=new ArrayList<>();
                    for(int j=0;j<l8.size();j++){
                        c8.add(JSON.parseObject(l8.get(j),CourseItem.class));
                    }

                    AllCourseWeekList eigCourseWeekList=new AllCourseWeekList();
                    eigCourseWeekList.setIndexCourseList(c8);
                    allCourseAllList.setEigCourseWeekList(eigCourseWeekList);
                    break;
                case 9:
                    String r9=list.get(8).getConnect();
                    List<String> l9=JSON.parseArray(r9,String.class);
                    List<CourseItem> c9=new ArrayList<>();
                    for(int j=0;j<l9.size();j++){
                        c9.add(JSON.parseObject(l9.get(j),CourseItem.class));
                    }

                    AllCourseWeekList nineCourseWeekList=new AllCourseWeekList();
                    nineCourseWeekList.setIndexCourseList(c9);
                    allCourseAllList.setNineCourseWeekList(nineCourseWeekList);
                    break;
                case 10:
                    String r10=list.get(9).getConnect();
                    List<String> l10=JSON.parseArray(r10,String.class);
                    List<CourseItem> c10=new ArrayList<>();
                    for(int j=0;j<l10.size();j++){
                        c10.add(JSON.parseObject(l10.get(j),CourseItem.class));
                    }

                    AllCourseWeekList tenCourseWeekList=new AllCourseWeekList();
                    tenCourseWeekList.setIndexCourseList(c10);
                    allCourseAllList.setTenCourseWeekList(tenCourseWeekList);
                    break;
                case 11:
                    String r11=list.get(10).getConnect();
                    List<String> l11=JSON.parseArray(r11,String.class);
                    List<CourseItem> c11=new ArrayList<>();
                    for(int j=0;j<l11.size();j++){
                        c11.add(JSON.parseObject(l11.get(j),CourseItem.class));
                    }

                    AllCourseWeekList elevenCourseWeekList=new AllCourseWeekList();
                    elevenCourseWeekList.setIndexCourseList(c11);
                    allCourseAllList.setElevenCourseWeekList(elevenCourseWeekList);
                    break;
                case 12:
                    String r12=list.get(11).getConnect();
                    List<String> l12=JSON.parseArray(r12,String.class);
                    List<CourseItem> c12=new ArrayList<>();
                    for(int j=0;j<l12.size();j++){
                        c12.add(JSON.parseObject(l12.get(j),CourseItem.class));
                    }

                    AllCourseWeekList twelveCourseWeekList=new AllCourseWeekList();
                    twelveCourseWeekList.setIndexCourseList(c12);
                    allCourseAllList.setTwelveCourseWeekList(twelveCourseWeekList);
                    break;
                case 13:
                    String r13=list.get(12).getConnect();
                    List<String> l13=JSON.parseArray(r13,String.class);
                    List<CourseItem> c13=new ArrayList<>();
                    for(int j=0;j<l13.size();j++){
                        c13.add(JSON.parseObject(l13.get(j),CourseItem.class));
                    }

                    AllCourseWeekList thirteenCourseWeekList=new AllCourseWeekList();
                    thirteenCourseWeekList.setIndexCourseList(c13);
                    allCourseAllList.setThirteenCourseWeekList(thirteenCourseWeekList);
                    break;
                case 14:
                    String r14=list.get(13).getConnect();
                    List<String> l14=JSON.parseArray(r14,String.class);
                    List<CourseItem> c14=new ArrayList<>();
                    for(int j=0;j<l14.size();j++){
                        c14.add(JSON.parseObject(l14.get(j),CourseItem.class));
                    }

                    AllCourseWeekList fourteenCourseWeekList=new AllCourseWeekList();
                    fourteenCourseWeekList.setIndexCourseList(c14);
                    allCourseAllList.setFourteenCourseWeekList(fourteenCourseWeekList);
                    break;
                case 15:
                    String r15=list.get(14).getConnect();
                    List<String> l15=JSON.parseArray(r15,String.class);
                    List<CourseItem> c15=new ArrayList<>();
                    for(int j=0;j<l15.size();j++){
                        c15.add(JSON.parseObject(l15.get(j),CourseItem.class));
                    }

                    AllCourseWeekList fifteenCourseWeekList=new AllCourseWeekList();
                    fifteenCourseWeekList.setIndexCourseList(c15);
                    allCourseAllList.setFifteenCourseWeekList(fifteenCourseWeekList);
                    break;
                case 16:
                    String r16=list.get(15).getConnect();
                    List<String> l16=JSON.parseArray(r16,String.class);
                    List<CourseItem> c16=new ArrayList<>();
                    for(int j=0;j<l16.size();j++){
                        c16.add(JSON.parseObject(l16.get(j),CourseItem.class));
                    }

                    AllCourseWeekList sixteenCourseWeekList=new AllCourseWeekList();
                    sixteenCourseWeekList.setIndexCourseList(c16);
                    allCourseAllList.setSixCourseWeekList(sixteenCourseWeekList);
                    break;
                case 17:
                    String r17=list.get(16).getConnect();
                    List<String> l17=JSON.parseArray(r17,String.class);
                    List<CourseItem> c17=new ArrayList<>();
                    for(int j=0;j<l17.size();j++){
                        c17.add(JSON.parseObject(l17.get(j),CourseItem.class));
                    }

                    AllCourseWeekList seventeenCourseWeekList=new AllCourseWeekList();
                    seventeenCourseWeekList.setIndexCourseList(c17);
                    allCourseAllList.setSeventeenCourseWeekList(seventeenCourseWeekList);
                    break;
                case 18:
                    String r18=list.get(17).getConnect();
                    List<String> l18=JSON.parseArray(r18,String.class);
                    List<CourseItem> c18=new ArrayList<>();
                    for(int j=0;j<l18.size();j++){
                        c18.add(JSON.parseObject(l18.get(j),CourseItem.class));
                    }

                    AllCourseWeekList eighteenCourseWeekList=new AllCourseWeekList();
                    eighteenCourseWeekList.setIndexCourseList(c18);
                    allCourseAllList.setEighteenCourseWeekList(eighteenCourseWeekList);
                    break;
                case 19:
                    String r19=list.get(18).getConnect();
                    List<String> l19=JSON.parseArray(r19,String.class);
                    List<CourseItem> c19=new ArrayList<>();
                    for(int j=0;j<l19.size();j++){
                        c19.add(JSON.parseObject(l19.get(j),CourseItem.class));
                    }

                    AllCourseWeekList nineteenCourseWeekList=new AllCourseWeekList();
                    nineteenCourseWeekList.setIndexCourseList(c19);
                    allCourseAllList.setNineteenCourseWeekList(nineteenCourseWeekList);
                    break;
                case 20:
                    String r20=list.get(19).getConnect();
                    List<String> l20=JSON.parseArray(r20,String.class);
                    List<CourseItem> c20=new ArrayList<>();
                    for(int j=0;j<l20.size();j++){
                        c20.add(JSON.parseObject(l20.get(j),CourseItem.class));
                    }

                    AllCourseWeekList twentyCourseWeekList=new AllCourseWeekList();
                    twentyCourseWeekList.setIndexCourseList(c20);
                    allCourseAllList.setTwentyCourseWeekList(twentyCourseWeekList);
                    break;
            }

        }

        return allCourseAllList;
    }



    @Override
    public AllCourseAllList getAllCourseByClassTask(String student_id, String jsessionid) {

        /**
         * 1.先根据学号查出所有的上课任务
         * 2.根据任务号查出所有课程
         * 3.复用以前的方法,添加课表
         */

        //1.查出所有的上课任务

        Map<String,Object> map=new HashMap<>();
        map.put("xnxqdm",CommonXQ.KCB);
        map.put("page",1);
        map.put("rows",33);
        map.put("sort","kcbh");
        map.put("order","asc");

        String classTaskJSON = HttpUnits.gyPost("https://jwxt.gdupt.edu.cn/xskktzd!getDataList.action",
                jsessionid, map);

        ClassTask classTask = JSON.parseObject(classTaskJSON, ClassTask.class);

        //2.根据上课任务查出所有课程

        Map<String,Object> itemMap=new HashMap<>();
        itemMap.put("xnxqdm",CommonXQ.KCB);
        itemMap.put("page",1);
        itemMap.put("rows",60);
        itemMap.put("sort","kxh");
        itemMap.put("order","asc");

        //所有课
        List<CourseItem> courseItemList=new ArrayList<>();

        for(int i=0;i<classTask.getTotal();i++){

            String kcrwd=classTask.getRows().get(i).kcrwdm;
            String itemCourseJSON = HttpUnits.gyPost(
                    "https://jwxt.gdupt.edu.cn/xskktzd!getZhouli.action?kcrwdm=" + kcrwd,
                    jsessionid, itemMap

            );

            //空的
            if(itemCourseJSON.contains("{\"total\":0")) {
                continue;
            }

            /**
             * "jcdm2":"07,08"  =>  jcdm 0708
             * zdjxcdmc     =>   jxcdmc
             */
            itemCourseJSON=itemCourseJSON.replace("zdjxcdmc",
                    "jxcdmc");

            int start = itemCourseJSON.indexOf("\"rows\":[")+7;
            int end= itemCourseJSON.length()-1;


            List<CourseItem> oneCourseList =
                    JSON.parseArray(itemCourseJSON.substring(start, end), CourseItem.class);

            String kcmc=classTask.getRows().get(i).kcmc;
            oneCourseList.forEach(item->{
                //设置课程名字
                item.setKcmc(kcmc);
                item.setJcdm(item.getJcdm2().replace(",",""));

                courseItemList.add(item);
            });


        }



        AllCourseAllList allCourseAllList=new AllCourseAllList();

        assembleCourse(allCourseAllList,courseItemList);

        //入库
        unitsCourseService.saveCourse(allCourseAllList,student_id);

        return allCourseAllList;
    }

}
